package com.cloudsigns.factorymanager2.engineering.model;

import android.text.TextUtils;

import com.cloudsigns.factorymanager2.MyApplicaton;
import com.cloudsigns.factorymanager2.cusenum.CommonEnum;
import com.cloudsigns.factorymanager2.engineering.bean.MaintainForPatrolBean;
import com.cloudsigns.factorymanager2.engineering.bean.MediaBean;
import com.cloudsigns.factorymanager2.engineering.bean.PatrolFeedbackBean;
import com.cloudsigns.factorymanager2.engineering.bean.PatrolOrderBean;
import com.cloudsigns.factorymanager2.engineering.utils.EngineeringUtil;
import com.cloudsigns.factorymanager2.project.utils.ConstantUtil;
import com.cloudsigns.factorymanager2.project.utils.ProjectUtil;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * Created by tony on 2018/5/8.
 */

public class PatrolOrderDetailModel implements IPatrolOrderDetailModel {


    @Override
    public void getPatrolOrderDetail(final String orderId, final String itemId, final OnPatrolOrderDetailModelListener patrolOrderDetailModelListener) {
        new Thread(new Runnable() {
            @Override
            public void run() {

                try {
                    String url = ProjectUtil.PATROL_ORDER_DETAIL + "?orderId=" + orderId;
                    if (!TextUtils.isEmpty(itemId)) {
                        url = url + "&itemId=" + itemId;
                    }
                    HttpClient client = new DefaultHttpClient();
                    HttpGet httpGet = new HttpGet(url);

                    HttpResponse response;

                    httpGet.addHeader("token", MyApplicaton.getApplication().getToken());
                    httpGet.addHeader(HTTP.CONTENT_TYPE, ConstantUtil.CONTENT_TYPE);


                    response = client.execute(httpGet);
                    String result = EntityUtils.toString(response.getEntity(), "UTF-8").trim();
                    JSONObject json = new JSONObject(result);
                    String code = json.getString("code");
                    if (null != patrolOrderDetailModelListener) {
                        if (code.equals(EngineeringUtil.HTTP_SUCCESSED_COD)) {
                            JSONObject dataJsonObj = new JSONObject(json.getString("data"));
                            PatrolOrderBean orderBean = new PatrolOrderBean();

                            String adminConfirmCompleteDate = dataJsonObj.getString("adminConfirmCompleteDate");
                            if (!TextUtils.isEmpty(adminConfirmCompleteDate) && !adminConfirmCompleteDate.equals("null")) {
                                orderBean.setAdminConfirmCompleteDate(Long.parseLong(adminConfirmCompleteDate));
                            }


                            String beginDate = dataJsonObj.getString("beginDate");
                            if (!TextUtils.isEmpty(beginDate) && !beginDate.equals("null")) {
                                orderBean.setBeginDate(Long.parseLong(beginDate));
                            }
                            orderBean.setCompanyId(dataJsonObj.getString("companyId"));
                            orderBean.setCompanyName(dataJsonObj.getString("companyName"));

                            String completeDate = dataJsonObj.getString("completeDate");
                            if (!TextUtils.isEmpty(completeDate) && !completeDate.equals("null")) {
                                orderBean.setCompleteDate(Long.parseLong(completeDate));
                            }

                            String completeStatus = dataJsonObj.getString("completeStatus");
                            if (null != completeStatus) {
                                if (completeStatus.equals("WORKING")) {
                                    orderBean.setCompleteStatus(CommonEnum.CompleteStatus.WORKING);
                                } else if (completeStatus.equals("WORKER_COMPLETE")) {
                                    orderBean.setCompleteStatus(CommonEnum.CompleteStatus.WORKER_COMPLETE);
                                } else if (completeStatus.equals("ADMIN_COMPLETE")) {
                                    orderBean.setCompleteStatus(CommonEnum.CompleteStatus.ADMIN_COMPLETE);
                                } else if (completeStatus.equals("SUPERADMIN_COMPLETE")) {
                                    orderBean.setCompleteStatus(CommonEnum.CompleteStatus.SUPERADMIN_COMPLETE);
                                }
                            }

                            String createDate = dataJsonObj.getString("createDate");
                            if (!TextUtils.isEmpty(createDate) && !createDate.equals("null")) {
                                orderBean.setCreateDate(Long.parseLong(createDate));
                            }
                            orderBean.setCreateOrderAccountId(dataJsonObj.getString("createOrderAccountId"));
                            orderBean.setCreateOrderAccountName(dataJsonObj.getString("createOrderAccountName"));

                            String finishDate = dataJsonObj.getString("finishDate");
                            if (!TextUtils.isEmpty(finishDate) && !finishDate.equals("null")) {
                                orderBean.setFinishDate(Long.parseLong(finishDate));
                            }
                            orderBean.setHasPauseOrder(dataJsonObj.getBoolean("hasPauseOrder"));
                            orderBean.setId(dataJsonObj.getString("id"));


                            String mediaListJsonArrStr = dataJsonObj.getString("mediaList");
                            if (null == mediaListJsonArrStr || TextUtils.isEmpty(mediaListJsonArrStr) || mediaListJsonArrStr.equals("null")) {

                            } else {
                                JSONArray mediaListJsonArr = new JSONArray(mediaListJsonArrStr);

                                List<MediaBean> mediaBeanList = new ArrayList<MediaBean>();
                                for (int i = 0; i < mediaListJsonArr.length(); i++) {
                                    JSONObject mediaJsonObj = (JSONObject) mediaListJsonArr.get(i);
                                    MediaBean mediaBean = new MediaBean();

                                    mediaBean.setAreaName(mediaJsonObj.getString("areaName"));

                                    mediaBean.setAssignCompleteAccountId(mediaJsonObj.getString("assignCompleteAccountId"));
                                    mediaBean.setAssignCompleteAccountName(mediaJsonObj.getString("assignCompleteAccountName"));

                                    String assignCompleteOrderTime = mediaJsonObj.getString("assignCompleteOrderTime");
                                    if (!TextUtils.isEmpty(assignCompleteOrderTime) && !assignCompleteOrderTime.equals("null")) {
                                        mediaBean.setAssignCompleteOrderTime(Long.parseLong(assignCompleteOrderTime));
                                    }

                                    String assignCompleteStatus = mediaJsonObj.getString("assignCompleteStatus");
                                    if (null != assignCompleteStatus) {
                                        if (assignCompleteStatus.equals("WORKING")) {
                                            mediaBean.setAssignCompleteStatus(CommonEnum.CompleteStatus.WORKING);
                                        } else if (assignCompleteStatus.equals("WORKER_COMPLETE")) {
                                            mediaBean.setAssignCompleteStatus(CommonEnum.CompleteStatus.WORKER_COMPLETE);
                                        } else if (assignCompleteStatus.equals("ADMIN_COMPLETE")) {
                                            mediaBean.setAssignCompleteStatus(CommonEnum.CompleteStatus.ADMIN_COMPLETE);
                                        } else if (assignCompleteStatus.equals("SUPERADMIN_COMPLETE")) {
                                            mediaBean.setAssignCompleteStatus(CommonEnum.CompleteStatus.SUPERADMIN_COMPLETE);
                                        }
                                    }


                                    mediaBean.setAssignReceiveAccountId(mediaJsonObj.getString("assignReceiveAccountId"));
                                    mediaBean.setAssignReceiveAccountName(mediaJsonObj.getString("assignReceiveAccountName"));
                                    mediaBean.setAssignReceiveOrderId(mediaJsonObj.getString("assignReceiveOrderId"));

                                    String assignReceiveOrderTime = mediaJsonObj.getString("assignReceiveOrderTime");
                                    if (!TextUtils.isEmpty(assignReceiveOrderTime) && !assignReceiveOrderTime.equals("null")) {
                                        mediaBean.setAssignReceiveOrderTime(Long.parseLong(assignReceiveOrderTime));
                                    }
                                    String assignStatusStr = mediaJsonObj.getString("assignStatus");
                                    if (!TextUtils.isEmpty(assignStatusStr)) {
                                        if (assignStatusStr.equals("CREATED")) {
                                            mediaBean.setAssignStatus(CommonEnum.AssignStatus.CREATED);
                                        } else if (assignStatusStr.equals("EDITED")) {
                                            mediaBean.setAssignStatus(CommonEnum.AssignStatus.EDITED);
                                        } else if (assignStatusStr.equals("SEND")) {
                                            mediaBean.setAssignStatus(CommonEnum.AssignStatus.SEND);
                                        } else if (assignStatusStr.equals("RECEIVED")) {
                                            mediaBean.setAssignStatus(CommonEnum.AssignStatus.RECEIVED);
                                        } else if (assignStatusStr.equals("RETURNED")) {
                                            mediaBean.setAssignStatus(CommonEnum.AssignStatus.RETURNED);
                                        } else if (assignStatusStr.equals("COMPLETED")) {
                                            mediaBean.setAssignStatus(CommonEnum.AssignStatus.COMPLETED);
                                        }

                                    }

                                    mediaBean.setId(mediaJsonObj.getString("id"));
                                    mediaBean.setMediaName(mediaJsonObj.getString("mediaName"));
                                    mediaBean.setNumber(mediaJsonObj.getString("number"));
//                                    String positionXStr = mediaJsonObj.getString("positionX");
//                                    if (!TextUtils.isEmpty(positionXStr)) {
//                                        mediaBean.setPositionX(Double.parseDouble(positionXStr));
//                                    }
//
//                                    String positionYStr = mediaJsonObj.getString("positionY");
//                                    if (!TextUtils.isEmpty(positionYStr)) {
//                                        mediaBean.setPositionY(Double.parseDouble(positionYStr));
//                                    }
                                    mediaBean.setRegionId(mediaJsonObj.getString("regionId"));
                                    mediaBean.setRegionName(mediaJsonObj.getString("regionName"));


                                    mediaBeanList.add(mediaBean);

                                }
                                orderBean.setMediaList(mediaBeanList);

                            }


                            String patrolFeedbackListJsonArrStr = dataJsonObj.getString("patrolFeedbackList");
                            if (null == patrolFeedbackListJsonArrStr || TextUtils.isEmpty(patrolFeedbackListJsonArrStr) || patrolFeedbackListJsonArrStr.equals("null")) {

                            } else {
                                JSONArray patrolFeedbackListJsonArr = new JSONArray(patrolFeedbackListJsonArrStr);
                                List<PatrolFeedbackBean> patrolFeedbackBeanList = new ArrayList<PatrolFeedbackBean>();
                                for (int i = 0; i < patrolFeedbackListJsonArr.length(); i++) {
                                    JSONObject patrolFeedbackJsonObj = (JSONObject) patrolFeedbackListJsonArr.get(i);
                                    PatrolFeedbackBean patrolFeedbackBean = new PatrolFeedbackBean();

                                    patrolFeedbackBean.setAccountId(patrolFeedbackJsonObj.getString("accountId"));
                                    patrolFeedbackBean.setAccountName(patrolFeedbackJsonObj.getString("accountName"));
                                    patrolFeedbackBean.setBright(patrolFeedbackJsonObj.getString("bright"));
                                    patrolFeedbackBean.setCable(patrolFeedbackJsonObj.getString("cable"));
                                    patrolFeedbackBean.setCurrent(patrolFeedbackJsonObj.getString("current"));

                                    JSONArray environmentImgUrlListJsonArr = patrolFeedbackJsonObj.getJSONArray("environmentImgUrlList");
                                    if (null != environmentImgUrlListJsonArr) {
                                        List<String> imgUrlList = new ArrayList<String>();
                                        for (int j = 0; j < environmentImgUrlListJsonArr.length(); j++) {
                                            String str = (String) environmentImgUrlListJsonArr.get(j);
                                            imgUrlList.add(str);
                                        }
                                        patrolFeedbackBean.setEnvironmentImgUrlList(imgUrlList);
                                    }

                                    String feedbackDate = patrolFeedbackJsonObj.getString("feedbackDate");
                                    if (!TextUtils.isEmpty(feedbackDate) && !feedbackDate.equals("null")) {
                                        patrolFeedbackBean.setFeedbackDate(Long.parseLong(feedbackDate));
                                    }
                                    String handleDate = patrolFeedbackJsonObj.getString("handleDate");
                                    if (!TextUtils.isEmpty(handleDate) && !handleDate.equals("null")) {
                                        patrolFeedbackBean.setHandleDate(Long.parseLong(handleDate));
                                    }

                                    patrolFeedbackBean.setHandlerAccountId(patrolFeedbackJsonObj.getString("handlerAccountId"));
                                    patrolFeedbackBean.setHandlerAccountName(patrolFeedbackJsonObj.getString("handlerAccountName"));
                                    patrolFeedbackBean.setId(patrolFeedbackJsonObj.getString("id"));
                                    patrolFeedbackBean.setItemId(patrolFeedbackJsonObj.getString("itemId"));
                                    String liftsystemStr = patrolFeedbackJsonObj.getString("liftSystem");
                                    if (!TextUtils.isEmpty(liftsystemStr)) {
                                        if (liftsystemStr.equals("NORMAL"))
                                            patrolFeedbackBean.setLiftSystem(CommonEnum.LIFTSYSTEM.NORMAL);
                                        else if (liftsystemStr.equals("SHIELD"))
                                            patrolFeedbackBean.setLiftSystem(CommonEnum.LIFTSYSTEM.SHIELD);
                                        else if (liftsystemStr.equals("LEAK"))
                                            patrolFeedbackBean.setLiftSystem(CommonEnum.LIFTSYSTEM.LEAK);
                                        else if (liftsystemStr.equals("RUST"))
                                            patrolFeedbackBean.setLiftSystem(CommonEnum.LIFTSYSTEM.RUST);
                                        else if (liftsystemStr.equals("VARIANT"))
                                            patrolFeedbackBean.setLiftSystem(CommonEnum.LIFTSYSTEM.VARIANT);
                                        else if (liftsystemStr.equals("LOOSE"))
                                            patrolFeedbackBean.setLiftSystem(CommonEnum.LIFTSYSTEM.LOOSE);
                                        else if (liftsystemStr.equals("MALFUNCTION"))
                                            patrolFeedbackBean.setLiftSystem(CommonEnum.LIFTSYSTEM.MALFUNCTION);
                                        else if (liftsystemStr.equals("WEAR"))
                                            patrolFeedbackBean.setLiftSystem(CommonEnum.LIFTSYSTEM.WEAR);
                                        else if (liftsystemStr.equals("NOT_CLEAN"))
                                            patrolFeedbackBean.setLiftSystem(CommonEnum.LIFTSYSTEM.NOT_CLEAN);
                                        else if (liftsystemStr.equals("PLICATED"))
                                            patrolFeedbackBean.setLiftSystem(CommonEnum.LIFTSYSTEM.PLICATED);
                                        else if (liftsystemStr.equals("TEAR"))
                                            patrolFeedbackBean.setLiftSystem(CommonEnum.LIFTSYSTEM.TEAR);
                                        else if (liftsystemStr.equals("SCRATCH"))
                                            patrolFeedbackBean.setLiftSystem(CommonEnum.LIFTSYSTEM.SCRATCH);

                                    }
                                    patrolFeedbackBean.setLight(patrolFeedbackJsonObj.getString("light"));

                                    JSONArray maintainListJsonArr = patrolFeedbackJsonObj.getJSONArray("maintainList");
                                    if (null != maintainListJsonArr) {
                                        List<MaintainForPatrolBean> maintainForPatrolBeanList = new ArrayList<MaintainForPatrolBean>();
                                        for (int j = 0; j < maintainListJsonArr.length(); j++) {
                                            JSONObject jsonObject = (JSONObject) maintainListJsonArr.get(j);
                                            MaintainForPatrolBean maintainForPatrolBean = new MaintainForPatrolBean();

                                            maintainForPatrolBean.setHandleId(jsonObject.getString("handleId"));
                                            maintainForPatrolBean.setHandle(jsonObject.getBoolean("isHandle"));

                                            String patrolFeedbackCategoryEnum = jsonObject.getString("patrolFeedbackCategoryEnum");
                                            if ("NORMAL".equals(patrolFeedbackCategoryEnum)) {
                                                maintainForPatrolBean.setPatrolFeedbackCategoryEnum(CommonEnum.LIFTSYSTEM.NORMAL);
                                            } else if ("SHIELD".equals(patrolFeedbackCategoryEnum)) {
                                                maintainForPatrolBean.setPatrolFeedbackCategoryEnum(CommonEnum.LIFTSYSTEM.SHIELD);
                                            } else if ("LEAK".equals(patrolFeedbackCategoryEnum)) {
                                                maintainForPatrolBean.setPatrolFeedbackCategoryEnum(CommonEnum.LIFTSYSTEM.LEAK);
                                            } else if ("RUST".equals(patrolFeedbackCategoryEnum)) {
                                                maintainForPatrolBean.setPatrolFeedbackCategoryEnum(CommonEnum.LIFTSYSTEM.RUST);
                                            } else if ("VARIANT".equals(patrolFeedbackCategoryEnum)) {
                                                maintainForPatrolBean.setPatrolFeedbackCategoryEnum(CommonEnum.LIFTSYSTEM.VARIANT);
                                            } else if ("LOOSE".equals(patrolFeedbackCategoryEnum)) {
                                                maintainForPatrolBean.setPatrolFeedbackCategoryEnum(CommonEnum.LIFTSYSTEM.LOOSE);
                                            } else if ("MALFUNCTION".equals(patrolFeedbackCategoryEnum)) {
                                                maintainForPatrolBean.setPatrolFeedbackCategoryEnum(CommonEnum.LIFTSYSTEM.MALFUNCTION);
                                            } else if ("WEAR".equals(patrolFeedbackCategoryEnum)) {
                                                maintainForPatrolBean.setPatrolFeedbackCategoryEnum(CommonEnum.LIFTSYSTEM.WEAR);
                                            } else if ("NOT_CLEAN".equals(patrolFeedbackCategoryEnum)) {
                                                maintainForPatrolBean.setPatrolFeedbackCategoryEnum(CommonEnum.LIFTSYSTEM.NOT_CLEAN);
                                            } else if ("PLICATED".equals(patrolFeedbackCategoryEnum)) {
                                                maintainForPatrolBean.setPatrolFeedbackCategoryEnum(CommonEnum.LIFTSYSTEM.PLICATED);
                                            } else if ("TEAR".equals(patrolFeedbackCategoryEnum)) {
                                                maintainForPatrolBean.setPatrolFeedbackCategoryEnum(CommonEnum.LIFTSYSTEM.TEAR);
                                            } else if ("SCRATCH".equals(patrolFeedbackCategoryEnum)) {
                                                maintainForPatrolBean.setPatrolFeedbackCategoryEnum(CommonEnum.LIFTSYSTEM.SCRATCH);
                                            }


                                            String patrolFeedbackItemEnum = jsonObject.getString("patrolFeedbackItemEnum");
                                            if("useEnvironment".equals(patrolFeedbackItemEnum)){
                                                maintainForPatrolBean.setPatrolFeedbackItemEnum(CommonEnum.MaintainList.useEnvironment);
                                            }else if("waterProofEnvironment".equals(patrolFeedbackItemEnum)){
                                                maintainForPatrolBean.setPatrolFeedbackItemEnum(CommonEnum.MaintainList.waterProofEnvironment);
                                            }else if("majorStructure".equals(patrolFeedbackItemEnum)){
                                                maintainForPatrolBean.setPatrolFeedbackItemEnum(CommonEnum.MaintainList.majorStructure);
                                            }else if("safeLock".equals(patrolFeedbackItemEnum)){
                                                maintainForPatrolBean.setPatrolFeedbackItemEnum(CommonEnum.MaintainList.safeLock);
                                            }else if("liftSystem".equals(patrolFeedbackItemEnum)){
                                                maintainForPatrolBean.setPatrolFeedbackItemEnum(CommonEnum.MaintainList.liftSystem);
                                            }else if("pulley".equals(patrolFeedbackItemEnum)){
                                                maintainForPatrolBean.setPatrolFeedbackItemEnum(CommonEnum.MaintainList.pulley);
                                            }else if("outline".equals(patrolFeedbackItemEnum)){
                                                maintainForPatrolBean.setPatrolFeedbackItemEnum(CommonEnum.MaintainList.outline);
                                            }else if("picture".equals(patrolFeedbackItemEnum)){
                                                maintainForPatrolBean.setPatrolFeedbackItemEnum(CommonEnum.MaintainList.picture);
                                            }


                                            maintainForPatrolBeanList.add(maintainForPatrolBean);
                                        }


                                        patrolFeedbackBean.setMaintainList(maintainForPatrolBeanList);

                                    }

                                    JSONArray majorImgUrlListJsonArr = patrolFeedbackJsonObj.getJSONArray("majorImgUrlList");
                                    if (null != majorImgUrlListJsonArr) {
                                        List<String> imgUrlList = new ArrayList<String>();
                                        for (int j = 0; j < majorImgUrlListJsonArr.length(); j++) {
                                            String str = (String) majorImgUrlListJsonArr.get(j);
                                            imgUrlList.add(str);
                                        }
                                        patrolFeedbackBean.setMajorImgUrlList(imgUrlList);
                                    }


                                    String majorStructureStr = patrolFeedbackJsonObj.getString("majorStructure");
                                    if (!TextUtils.isEmpty(majorStructureStr)) {
                                        if (majorStructureStr.equals("NORMAL"))
                                            patrolFeedbackBean.setMajorStructure(CommonEnum.LIFTSYSTEM.NORMAL);
                                        else if (majorStructureStr.equals("SHIELD"))
                                            patrolFeedbackBean.setMajorStructure(CommonEnum.LIFTSYSTEM.SHIELD);
                                        else if (majorStructureStr.equals("LEAK"))
                                            patrolFeedbackBean.setMajorStructure(CommonEnum.LIFTSYSTEM.LEAK);
                                        else if (majorStructureStr.equals("RUST"))
                                            patrolFeedbackBean.setMajorStructure(CommonEnum.LIFTSYSTEM.RUST);
                                        else if (majorStructureStr.equals("VARIANT"))
                                            patrolFeedbackBean.setMajorStructure(CommonEnum.LIFTSYSTEM.VARIANT);
                                        else if (majorStructureStr.equals("LOOSE"))
                                            patrolFeedbackBean.setMajorStructure(CommonEnum.LIFTSYSTEM.LOOSE);
                                        else if (majorStructureStr.equals("MALFUNCTION"))
                                            patrolFeedbackBean.setMajorStructure(CommonEnum.LIFTSYSTEM.MALFUNCTION);
                                        else if (majorStructureStr.equals("WEAR"))
                                            patrolFeedbackBean.setMajorStructure(CommonEnum.LIFTSYSTEM.WEAR);
                                        else if (majorStructureStr.equals("NOT_CLEAN"))
                                            patrolFeedbackBean.setMajorStructure(CommonEnum.LIFTSYSTEM.NOT_CLEAN);
                                        else if (majorStructureStr.equals("PLICATED"))
                                            patrolFeedbackBean.setMajorStructure(CommonEnum.LIFTSYSTEM.PLICATED);
                                        else if (majorStructureStr.equals("TEAR"))
                                            patrolFeedbackBean.setMajorStructure(CommonEnum.LIFTSYSTEM.TEAR);
                                        else if (majorStructureStr.equals("SCRATCH"))
                                            patrolFeedbackBean.setMajorStructure(CommonEnum.LIFTSYSTEM.SCRATCH);

                                    }

                                    patrolFeedbackBean.setOn_off(patrolFeedbackJsonObj.getString("on_off"));
                                    String outlineStr = patrolFeedbackJsonObj.getString("outline");
                                    if (!TextUtils.isEmpty(outlineStr)) {
                                        if (outlineStr.equals("NORMAL"))
                                            patrolFeedbackBean.setOutline(CommonEnum.LIFTSYSTEM.NORMAL);
                                        else if (outlineStr.equals("SHIELD"))
                                            patrolFeedbackBean.setOutline(CommonEnum.LIFTSYSTEM.SHIELD);
                                        else if (outlineStr.equals("LEAK"))
                                            patrolFeedbackBean.setOutline(CommonEnum.LIFTSYSTEM.LEAK);
                                        else if (outlineStr.equals("RUST"))
                                            patrolFeedbackBean.setOutline(CommonEnum.LIFTSYSTEM.RUST);
                                        else if (outlineStr.equals("VARIANT"))
                                            patrolFeedbackBean.setOutline(CommonEnum.LIFTSYSTEM.VARIANT);
                                        else if (outlineStr.equals("LOOSE"))
                                            patrolFeedbackBean.setOutline(CommonEnum.LIFTSYSTEM.LOOSE);
                                        else if (outlineStr.equals("MALFUNCTION"))
                                            patrolFeedbackBean.setOutline(CommonEnum.LIFTSYSTEM.MALFUNCTION);
                                        else if (outlineStr.equals("WEAR"))
                                            patrolFeedbackBean.setOutline(CommonEnum.LIFTSYSTEM.WEAR);
                                        else if (outlineStr.equals("NOT_CLEAN"))
                                            patrolFeedbackBean.setOutline(CommonEnum.LIFTSYSTEM.NOT_CLEAN);
                                        else if (outlineStr.equals("PLICATED"))
                                            patrolFeedbackBean.setOutline(CommonEnum.LIFTSYSTEM.PLICATED);
                                        else if (outlineStr.equals("TEAR"))
                                            patrolFeedbackBean.setOutline(CommonEnum.LIFTSYSTEM.TEAR);
                                        else if (outlineStr.equals("SCRATCH"))
                                            patrolFeedbackBean.setOutline(CommonEnum.LIFTSYSTEM.SCRATCH);

                                    }

                                    String pictureStr = patrolFeedbackJsonObj.getString("picture");
                                    if (!TextUtils.isEmpty(pictureStr)) {
                                        if (pictureStr.equals("NORMAL"))
                                            patrolFeedbackBean.setPicture(CommonEnum.LIFTSYSTEM.NORMAL);
                                        else if (pictureStr.equals("SHIELD"))
                                            patrolFeedbackBean.setPicture(CommonEnum.LIFTSYSTEM.SHIELD);
                                        else if (pictureStr.equals("LEAK"))
                                            patrolFeedbackBean.setPicture(CommonEnum.LIFTSYSTEM.LEAK);
                                        else if (pictureStr.equals("RUST"))
                                            patrolFeedbackBean.setPicture(CommonEnum.LIFTSYSTEM.RUST);
                                        else if (pictureStr.equals("VARIANT"))
                                            patrolFeedbackBean.setPicture(CommonEnum.LIFTSYSTEM.VARIANT);
                                        else if (pictureStr.equals("LOOSE"))
                                            patrolFeedbackBean.setPicture(CommonEnum.LIFTSYSTEM.LOOSE);
                                        else if (pictureStr.equals("MALFUNCTION"))
                                            patrolFeedbackBean.setPicture(CommonEnum.LIFTSYSTEM.MALFUNCTION);
                                        else if (pictureStr.equals("WEAR"))
                                            patrolFeedbackBean.setPicture(CommonEnum.LIFTSYSTEM.WEAR);
                                        else if (pictureStr.equals("NOT_CLEAN"))
                                            patrolFeedbackBean.setPicture(CommonEnum.LIFTSYSTEM.NOT_CLEAN);
                                        else if (pictureStr.equals("PLICATED"))
                                            patrolFeedbackBean.setPicture(CommonEnum.LIFTSYSTEM.PLICATED);
                                        else if (pictureStr.equals("TEAR"))
                                            patrolFeedbackBean.setPicture(CommonEnum.LIFTSYSTEM.TEAR);
                                        else if (pictureStr.equals("SCRATCH"))
                                            patrolFeedbackBean.setPicture(CommonEnum.LIFTSYSTEM.SCRATCH);

                                    }
                                    patrolFeedbackBean.setPort(patrolFeedbackJsonObj.getString("port"));
                                    patrolFeedbackBean.setPower(patrolFeedbackJsonObj.getString("power"));
                                    JSONArray preserveListJsonArr = patrolFeedbackJsonObj.getJSONArray("preserveList");
                                    if (null != preserveListJsonArr) {
                                        List<CommonEnum.PRESERVELIST> preservelist = new ArrayList<CommonEnum.PRESERVELIST>();
                                        for (int j = 0; j < preserveListJsonArr.length(); j++) {
                                            String str = (String) preserveListJsonArr.get(j);
                                            if (null != str) {
                                                if (str.equals("OUT_CLEAN"))
                                                    preservelist.add(CommonEnum.PRESERVELIST.OUT_CLEAN);
                                                if (str.equals("IN_CLEAN"))
                                                    preservelist.add(CommonEnum.PRESERVELIST.IN_CLEAN);
                                                if (str.equals("CABLE_PORT"))
                                                    preservelist.add(CommonEnum.PRESERVELIST.CABLE_PORT);
                                                if (str.equals("PLUG"))
                                                    preservelist.add(CommonEnum.PRESERVELIST.PLUG);
                                                if (str.equals("BOX_BOLT"))
                                                    preservelist.add(CommonEnum.PRESERVELIST.BOX_BOLT);
                                                if (str.equals("LIGHT_POWER"))
                                                    preservelist.add(CommonEnum.PRESERVELIST.LIGHT_POWER);
                                            }
                                        }

                                        patrolFeedbackBean.setPreserveList(preservelist);
                                    }

                                    String pulleyStr = patrolFeedbackJsonObj.getString("pulley");
                                    if (!TextUtils.isEmpty(pulleyStr)) {
                                        if (pulleyStr.equals("NORMAL"))
                                            patrolFeedbackBean.setPulley(CommonEnum.LIFTSYSTEM.NORMAL);
                                        else if (pulleyStr.equals("SHIELD"))
                                            patrolFeedbackBean.setPulley(CommonEnum.LIFTSYSTEM.SHIELD);
                                        else if (pulleyStr.equals("LEAK"))
                                            patrolFeedbackBean.setPulley(CommonEnum.LIFTSYSTEM.LEAK);
                                        else if (pulleyStr.equals("RUST"))
                                            patrolFeedbackBean.setPulley(CommonEnum.LIFTSYSTEM.RUST);
                                        else if (pulleyStr.equals("VARIANT"))
                                            patrolFeedbackBean.setPulley(CommonEnum.LIFTSYSTEM.VARIANT);
                                        else if (pulleyStr.equals("LOOSE"))
                                            patrolFeedbackBean.setPulley(CommonEnum.LIFTSYSTEM.LOOSE);
                                        else if (pulleyStr.equals("MALFUNCTION"))
                                            patrolFeedbackBean.setPulley(CommonEnum.LIFTSYSTEM.MALFUNCTION);
                                        else if (pulleyStr.equals("WEAR"))
                                            patrolFeedbackBean.setPulley(CommonEnum.LIFTSYSTEM.WEAR);
                                        else if (pulleyStr.equals("NOT_CLEAN"))
                                            patrolFeedbackBean.setPulley(CommonEnum.LIFTSYSTEM.NOT_CLEAN);
                                        else if (pulleyStr.equals("PLICATED"))
                                            patrolFeedbackBean.setPulley(CommonEnum.LIFTSYSTEM.PLICATED);
                                        else if (pulleyStr.equals("TEAR"))
                                            patrolFeedbackBean.setPulley(CommonEnum.LIFTSYSTEM.TEAR);
                                        else if (pulleyStr.equals("SCRATCH"))
                                            patrolFeedbackBean.setPulley(CommonEnum.LIFTSYSTEM.SCRATCH);
                                    }

                                    String safeLockStr = patrolFeedbackJsonObj.getString("safeLock");
                                    if (!TextUtils.isEmpty(safeLockStr)) {
                                        if (safeLockStr.equals("NORMAL"))
                                            patrolFeedbackBean.setSafeLock(CommonEnum.LIFTSYSTEM.NORMAL);
                                        else if (safeLockStr.equals("SHIELD"))
                                            patrolFeedbackBean.setSafeLock(CommonEnum.LIFTSYSTEM.SHIELD);
                                        else if (safeLockStr.equals("LEAK"))
                                            patrolFeedbackBean.setSafeLock(CommonEnum.LIFTSYSTEM.LEAK);
                                        else if (safeLockStr.equals("RUST"))
                                            patrolFeedbackBean.setSafeLock(CommonEnum.LIFTSYSTEM.RUST);
                                        else if (safeLockStr.equals("VARIANT"))
                                            patrolFeedbackBean.setSafeLock(CommonEnum.LIFTSYSTEM.VARIANT);
                                        else if (safeLockStr.equals("LOOSE"))
                                            patrolFeedbackBean.setSafeLock(CommonEnum.LIFTSYSTEM.LOOSE);
                                        else if (safeLockStr.equals("MALFUNCTION"))
                                            patrolFeedbackBean.setSafeLock(CommonEnum.LIFTSYSTEM.MALFUNCTION);
                                        else if (safeLockStr.equals("WEAR"))
                                            patrolFeedbackBean.setSafeLock(CommonEnum.LIFTSYSTEM.WEAR);
                                        else if (safeLockStr.equals("NOT_CLEAN"))
                                            patrolFeedbackBean.setSafeLock(CommonEnum.LIFTSYSTEM.NOT_CLEAN);
                                        else if (safeLockStr.equals("PLICATED"))
                                            patrolFeedbackBean.setSafeLock(CommonEnum.LIFTSYSTEM.PLICATED);
                                        else if (safeLockStr.equals("TEAR"))
                                            patrolFeedbackBean.setSafeLock(CommonEnum.LIFTSYSTEM.TEAR);
                                        else if (safeLockStr.equals("SCRATCH"))
                                            patrolFeedbackBean.setSafeLock(CommonEnum.LIFTSYSTEM.SCRATCH);
                                    }

                                    patrolFeedbackBean.setTemperature(patrolFeedbackJsonObj.getString("temperature"));
                                    String typeStr = patrolFeedbackJsonObj.getString("type");
                                    if (!TextUtils.isEmpty(typeStr)) {
                                        if (typeStr.equals("NORMAL"))
                                            patrolFeedbackBean.setType(CommonEnum.FeedBackType.NORMAL);
                                        else if (typeStr.equals("UNUSUAL"))
                                            patrolFeedbackBean.setType(CommonEnum.FeedBackType.UNUSUAL);
                                        else if (typeStr.equals("COMPLETED"))
                                            patrolFeedbackBean.setType(CommonEnum.FeedBackType.COMPLETED);
                                    }

                                    String useEnvironmentStr = patrolFeedbackJsonObj.getString("useEnvironment");
                                    if (!TextUtils.isEmpty(safeLockStr)) {
                                        if (useEnvironmentStr.equals("NORMAL"))
                                            patrolFeedbackBean.setUseEnvironment(CommonEnum.LIFTSYSTEM.NORMAL);
                                        else if (useEnvironmentStr.equals("SHIELD"))
                                            patrolFeedbackBean.setUseEnvironment(CommonEnum.LIFTSYSTEM.SHIELD);
                                        else if (useEnvironmentStr.equals("LEAK"))
                                            patrolFeedbackBean.setUseEnvironment(CommonEnum.LIFTSYSTEM.LEAK);
                                        else if (useEnvironmentStr.equals("RUST"))
                                            patrolFeedbackBean.setUseEnvironment(CommonEnum.LIFTSYSTEM.RUST);
                                        else if (useEnvironmentStr.equals("VARIANT"))
                                            patrolFeedbackBean.setUseEnvironment(CommonEnum.LIFTSYSTEM.VARIANT);
                                        else if (useEnvironmentStr.equals("LOOSE"))
                                            patrolFeedbackBean.setUseEnvironment(CommonEnum.LIFTSYSTEM.LOOSE);
                                        else if (useEnvironmentStr.equals("MALFUNCTION"))
                                            patrolFeedbackBean.setUseEnvironment(CommonEnum.LIFTSYSTEM.MALFUNCTION);
                                        else if (useEnvironmentStr.equals("WEAR"))
                                            patrolFeedbackBean.setUseEnvironment(CommonEnum.LIFTSYSTEM.WEAR);
                                        else if (useEnvironmentStr.equals("NOT_CLEAN"))
                                            patrolFeedbackBean.setUseEnvironment(CommonEnum.LIFTSYSTEM.NOT_CLEAN);
                                        else if (useEnvironmentStr.equals("PLICATED"))
                                            patrolFeedbackBean.setUseEnvironment(CommonEnum.LIFTSYSTEM.PLICATED);
                                        else if (useEnvironmentStr.equals("TEAR"))
                                            patrolFeedbackBean.setUseEnvironment(CommonEnum.LIFTSYSTEM.TEAR);
                                        else if (useEnvironmentStr.equals("SCRATCH"))
                                            patrolFeedbackBean.setUseEnvironment(CommonEnum.LIFTSYSTEM.SCRATCH);
                                    }

                                    patrolFeedbackBean.setVoltage(patrolFeedbackJsonObj.getString("voltage"));

                                    String waterProofEnvironmentStr = patrolFeedbackJsonObj.getString("waterProofEnvironment");
                                    if (!TextUtils.isEmpty(waterProofEnvironmentStr)) {
                                        if (waterProofEnvironmentStr.equals("NORMAL"))
                                            patrolFeedbackBean.setWaterProofEnvironment(CommonEnum.LIFTSYSTEM.NORMAL);
                                        else if (waterProofEnvironmentStr.equals("SHIELD"))
                                            patrolFeedbackBean.setWaterProofEnvironment(CommonEnum.LIFTSYSTEM.SHIELD);
                                        else if (waterProofEnvironmentStr.equals("LEAK"))
                                            patrolFeedbackBean.setWaterProofEnvironment(CommonEnum.LIFTSYSTEM.LEAK);
                                        else if (waterProofEnvironmentStr.equals("RUST"))
                                            patrolFeedbackBean.setWaterProofEnvironment(CommonEnum.LIFTSYSTEM.RUST);
                                        else if (waterProofEnvironmentStr.equals("VARIANT"))
                                            patrolFeedbackBean.setWaterProofEnvironment(CommonEnum.LIFTSYSTEM.VARIANT);
                                        else if (waterProofEnvironmentStr.equals("LOOSE"))
                                            patrolFeedbackBean.setWaterProofEnvironment(CommonEnum.LIFTSYSTEM.LOOSE);
                                        else if (waterProofEnvironmentStr.equals("MALFUNCTION"))
                                            patrolFeedbackBean.setWaterProofEnvironment(CommonEnum.LIFTSYSTEM.MALFUNCTION);
                                        else if (waterProofEnvironmentStr.equals("WEAR"))
                                            patrolFeedbackBean.setWaterProofEnvironment(CommonEnum.LIFTSYSTEM.WEAR);
                                        else if (waterProofEnvironmentStr.equals("NOT_CLEAN"))
                                            patrolFeedbackBean.setWaterProofEnvironment(CommonEnum.LIFTSYSTEM.NOT_CLEAN);
                                        else if (waterProofEnvironmentStr.equals("PLICATED"))
                                            patrolFeedbackBean.setWaterProofEnvironment(CommonEnum.LIFTSYSTEM.PLICATED);
                                        else if (waterProofEnvironmentStr.equals("TEAR"))
                                            patrolFeedbackBean.setWaterProofEnvironment(CommonEnum.LIFTSYSTEM.TEAR);
                                        else if (waterProofEnvironmentStr.equals("SCRATCH"))
                                            patrolFeedbackBean.setWaterProofEnvironment(CommonEnum.LIFTSYSTEM.SCRATCH);
                                    }

                                    patrolFeedbackBeanList.add(patrolFeedbackBean);

                                }

                                orderBean.setPatrolFeedbackList(patrolFeedbackBeanList);


                            }


                            orderBean.setReceiveAccountId(dataJsonObj.getString("receiveAccountId"));
                            orderBean.setReceiveAccountName(dataJsonObj.getString("receiveAccountName"));
                            String receiveOrderTime = dataJsonObj.getString("receiveOrderTime");
                            if (!TextUtils.isEmpty(receiveOrderTime) && !receiveOrderTime.equals("null")) {
                                orderBean.setFinishDate(Long.parseLong(receiveOrderTime));
                            }
                            orderBean.setRegionName(dataJsonObj.getString("regionName"));
                            String sendOrderTime = dataJsonObj.getString("sendOrderTime");
                            if (!TextUtils.isEmpty(sendOrderTime) && !sendOrderTime.equals("null")) {
                                orderBean.setSendOrderTime(Long.parseLong(sendOrderTime));
                            }

                            String statusStr = dataJsonObj.getString("status");
                            if (!TextUtils.isEmpty(statusStr)) {
                                if (statusStr.equals("CREATED")) {
                                    orderBean.setStatus(CommonEnum.EngineeringOrderStatus.CREATED);
                                } else if (statusStr.equals("SEND")) {
                                    orderBean.setStatus(CommonEnum.EngineeringOrderStatus.SEND);
                                } else if (statusStr.equals("RECEIVED")) {
                                    orderBean.setStatus(CommonEnum.EngineeringOrderStatus.RECEIVED);
                                } else if (statusStr.equals("RETURNED")) {
                                    orderBean.setStatus(CommonEnum.EngineeringOrderStatus.RETURNED);
                                } else if (statusStr.equals("COMPLETED")) {
                                    orderBean.setStatus(CommonEnum.EngineeringOrderStatus.COMPLETED);
                                }
                            }


                            patrolOrderDetailModelListener.getPatrolOrderDetailSuccessed(orderBean);

                        } else {
                            String error_str = code;
                            error_str += "," + ConstantUtil.getErrorCode(code);
                            if (!json.isNull("error_str")) {
                                error_str += "," + json.getString("error_str");
                            }
                            patrolOrderDetailModelListener.getPatrolOrderDetailFailed(error_str);
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {

                }
            }
        }).start();
    }

    public interface OnPatrolOrderDetailModelListener {
        void getPatrolOrderDetailSuccessed(PatrolOrderBean patrolOrderBean);

        void getPatrolOrderDetailFailed(String desc);
    }
}
